package main.mvc.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesParse {
	
	private Properties properties;
	private InputStream inputStream;
	
	public PropertiesParse() {
		properties = new Properties();
	}
	
	public  PropertiesParse(String fileName) {
		properties = new Properties();

		try {
			inputStream = PropertiesParse.class.getResourceAsStream(fileName);
		/*	if(inputStream == null){
				System.out.println("null");
			}*/
			properties.load(inputStream);
			inputStream.close();
			
		}  catch (FileNotFoundException e) {
			System.out.println("");
			e.printStackTrace();
		}  catch (IOException e) {
			System.out.println("");
			e.printStackTrace();
		}
	}
	
	
	public String getValue(String key){
        if(properties.containsKey(key)){
            String value = properties.getProperty(key);
            return value;
        }
        else
            return "";
    }
	

	public String getValue(String fileName, String key)
    {
        try{
            String value = "";
            inputStream = this.getClass().getResourceAsStream(fileName);
            properties.load(inputStream);
            inputStream.close();
            
            if(properties.containsKey(key)){
                value = properties.getProperty(key);
                return value;
            }else
                return value;
        } catch (FileNotFoundException e){
            e.printStackTrace();
            return "";
        } catch (IOException e){
            e.printStackTrace();
            return "";
        } catch (Exception ex){
            ex.printStackTrace();
            return "";
        }
    }

	public Properties getProperties() {
		return properties;
	}

	public void setProperties(Properties properties) {
		this.properties = properties;
	}

}
